﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignMode.Factory
{
    // 产品类
    public abstract class AbstractProuctA
    {
        public abstract void Print();
    }

    public class ProductA1 : AbstractProuctA
    {
        public override void Print()
        {
            Console.WriteLine("--产品A1--");
        }
    }

    public class ProductA2 : AbstractProuctA
    {
        public override void Print()
        {
            Console.WriteLine("--产品A2--");
        }
    }


    public abstract class AbstractProuctB
    {
        public abstract void Print();
    }

    public class ProductB1 : AbstractProuctB
    {
        public override void Print()
        {
            Console.WriteLine("--产品B1--");
        }
    }

    public class ProductB2 : AbstractProuctB
    {
        public override void Print()
        {
            Console.WriteLine("--产品B2--");
        }
    }

    //工厂类
    public abstract class AbstractFactory
    {
        public abstract AbstractProuctA CreateProductA();
        public abstract AbstractProuctB CreateProductB();
    }

    public class ConcreteFactory1:AbstractFactory
    {
        public override AbstractProuctA CreateProductA()
        {
            return new ProductA1();
        }

        public override AbstractProuctB CreateProductB()
        {
            return new ProductB1();
        }
    }

    public class ConcreteFactory2 : AbstractFactory
    {
        public override AbstractProuctA CreateProductA()
        {
            return new ProductA2();
        }

        public override AbstractProuctB CreateProductB()
        {
            return new ProductB2();
        }
    }
}
